<template>
  <div class="website-complete-container">
    <div class="complete-content">
      <!-- 标题和说明 -->
      <div class="title-section">
        <h2 class="main-title">微官网已生成，即刻启用～</h2>
        <p class="subtitle">
          您的微官网已完成全部配置，后续可根据需求<br />
          灵活调整模块布局、更新信息，助力品牌精准送达目标受众～
        </p>
        <button class="design-button" @click="onDesignClick">
          管理我的微官网
        </button>
      </div>

      <!-- 预览和二维码区域 -->
      <div class="preview-section">
        <!-- 预览设备展示 -->
        <div class="devices-showcase">
          <!-- 二维码和链接 -->
          <div class="qrcode-section">
            <div class="qrcode-wrapper">
              <QrcodeGenerator
                ref="customQrcode"
                :content="customQrcodeConfig.content"
                :size="customQrcodeConfig.size"
                :foreground-color="customQrcodeConfig.foregroundColor"
                :background-color="customQrcodeConfig.backgroundColor"
                :error-correction-level="
                  customQrcodeConfig.errorCorrectionLevel
                "
                @generated="handleQrcodeGenerated"
                @error="handleQrcodeError"
              />
              <!-- <img :src="qrcodeImage" alt="扫码预览" class="qrcode" /> -->
              <p class="qrcode-text">
                扫码预览<i
                  class="el-icon-download"
                  style="padding-left: 5px; color: #333; font-size: 17px"
                ></i>
              </p>
            </div>
            <div class="link-info">
              <p class="link-label">电脑端链接：</p>
              <p
                class="web-link"
                v-clipboard:copy="'https://example.com/payment-confirm'"
                v-clipboard:success="productNameCopySuccess"
                v-clipboard:error="productNameCopyError"
              >
                https://example.com/payment-confirm
                <i
                  class="el-icon-document-copy color-back"
                  style="padding-left: 10px"
                ></i>
              </p>
            </div>
          </div>

          <!-- 电脑预览 -->
          <div class="desktop-preview">
            <img
              :src="desktopPreviewImage"
              alt="电脑预览"
              class="desktop-image"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// / 引入二维码生成组件
import QrcodeGenerator from "@/components/public/QrcodeGenerrator.vue";
export default {
  name: "WebsiteComplete",
  components: {
    QrcodeGenerator,
  },
  props: {
    phonePreviewImage: {
      type: String,
      default: require("@/assets/template/step_back2.png"),
    },
    desktopPreviewImage: {
      type: String,
      default: require("@/assets/template/step_back2.png"),
    },
    qrcodeImage: {
      type: String,
      default: require("@/assets/template/qrcode_example.png"),
    },
  },
  data() {
    return {
      // 自定义二维码配置
      customQrcodeConfig: {
        content: "https://example.com/payment-confirm", // 二维码内容
        size: 100, //二维码大小
        foregroundColor: "#333333", //二维码颜色
        backgroundColor: "#ffffff", //二维码背景颜色
        errorCorrectionLevel: "M", //二维码错误 correction level
      },
    };
  },

  methods: {
    // 处理二维码生成成功事件
    handleQrcodeGenerated(canvas) {
      this.statusMessage = "二维码生成成功";
      this.statusType = "success";
      // 3秒后自动隐藏提示
      setTimeout(() => {
        this.statusMessage = "";
      }, 3000);
    },
    // 处理二维码生成错误事件
    handleQrcodeError(error) {
      this.statusMessage = `二维码生成失败: ${error.message}`;
      this.statusType = "error";
    },
    productNameCopySuccess() {
      this.$message({
        message: "已复制",
        type: "success",
      });
    },
    productNameCopyError() {
      this.$message({
        message: "复制失败",
        type: "error",
      });
    },
    onDesignClick() {
      this.$emit("design");
    },
  },
};
</script>

<style scoped>
.website-complete-container {
  width: 100%;
  /* min-height: 500px; */
  display: flex;
  align-items: center;
  justify-content: center;
  /* padding: 40px 0; */
  box-sizing: border-box;
}

.complete-content {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.title-section {
  text-align: center;
  margin-bottom: 10px;
}

.main-title {
  font-size: 24px;
  color: #333;
  margin-bottom: 16px;
  font-weight: bold;
}

.subtitle {
  font-size: 14px;
  color: #666;
  line-height: 1.8;
  margin-bottom: 24px;
}

.design-button {
  background-color: #348cf8;
  color: white;
  border: none;
  padding: 12px 36px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  font-weight: bold;
}

.design-button:hover {
  background-color: #40a9ff;
}

.preview-section {
  display: flex;
  align-items: center;
  gap: 60px;
  justify-content: center;
}

.devices-showcase {
  display: flex;
  align-items: center;
  gap: -40px;
  position: relative;
}

.phone-preview {
  z-index: 2;
}

.phone-image {
  width: 200px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.desktop-preview {
  position: relative;
  z-index: 1;
}

.desktop-image {
  max-height: 340px;
  height: auto;
  border-radius: 8px;
}

.qrcode-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.qrcode-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #fff;
  padding: 10px 10px 15px 10px;
  border-radius: 14px;
}

.qrcode {
  width: 120px;
  background-color: white;
  padding: 8px;
  /* border-radius: 8px; */
}

.qrcode-text {
  font-size: 13px;
  color: #666;
  margin: 0;
}

.link-info {
  flex-direction: column;
  gap: 8px;
  align-items: center;
  padding-left: 70px;
}

.link-label {
  font-size: 13px;
  color: #666;
  margin: 0;
  padding-bottom: 10px;
}

.web-link {
  font-size: 13px;
  /* color: #348CF8; */
  margin: 0;
  word-break: break-all;
  max-width: 200px;
  cursor: pointer;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .preview-section {
    flex-direction: column;
    gap: 40px;
  }

  .desktop-image {
    width: 400px;
  }
}

@media (max-width: 768px) {
  .main-title {
    font-size: 20px;
  }

  .devices-showcase {
    flex-direction: column;
    gap: 20px;
    align-items: center;
  }

  .desktop-image {
    width: 100%;
    max-width: 320px;
  }

  .phone-image {
    width: 160px;
  }
}
</style>
